#include "AddressResolutionException.h"

AddressResolutionException::AddressResolutionException(int errorCode)
{
  assignErrorDescription();
}

void AddressResolutionException::assignErrorDescription()
{ 
	switch(errorCode)
	{
		case HOST_NOT_FOUND:
      errorCode = ERROR_HOST_NOT_FOUND;
			description = ERROR_DESC_HOST_NOT_FOUND;
			break;
		
		case NO_DATA:
      errorCode = ERROR_INFO_UNAVAILABLE;
			description = ERROR_DESC_ADDRESS_INFO_UNAVAILABLE;
			break;
		
		case NO_RECOVERY:
    case EAI_FAIL:
      errorCode = ERROR_SERVER;
			description = ERROR_DESC_SERVER;
			break;
		
		case TRY_AGAIN:
    case EAI_AGAIN:
      errorCode = ERROR_RETRY_REQUIRED;
			description = ERROR_DESC_RETRY_REQUIRED;
			break;
                        
    case EAI_SYSTEM:
    case EAI_MEMORY:
    case EAI_OVERFLOW:
      errorCode = ERROR_SYSTEM;
			description = ERROR_DESC_SYSTEM;
			break;
                        
    default:
			description = ERROR_DESC_UNDEFINED;
			break;
	};
}

const string & AddressResolutionException::getDescription()
{
    return description;
}

const string AddressResolutionException::ERROR_DESC_HOST_NOT_FOUND = 
"No such host is known.";

const string AddressResolutionException::ERROR_DESC_INFO_UNAVAILABLE = 
"The server does not have address information for the requested hostname."; 

const string AddressResolutionException::ERROR_DESC_SERVER = 
"An unexpected server error has occurred.";

const string AddressResolutionException::ERROR_DESC_RETRY_REQUIRED = 
"A temporary error occurred, a retry may be required.";

const string AddressResolutionException::ERROR_DESC_SYSTEM =
"A system error has occurred.";

const string AddressResolutionException::ERROR_DESC_UNDEFINED =
"Unknown error";
